//
//  FirstViewController.m
//  B段项目
//
//  Created by dllo on 15/9/24.
//  Copyright (c) 2015年 昶博. All rights reserved.
//

#import "FirstViewController.h"
#import "PrefixHeader.pch"
#import "BarView.h"
#import "FirstScrollView.h"
#import "DetailsViewController.h"
#import "SearchBarViewController.h"
#import <RESideMenu.h>

@interface FirstViewController () <UISearchBarDelegate>

@property (nonatomic, strong) BarView *barView;

@end

@implementation FirstViewController

- (void)viewWillAppear:(BOOL)animated
{
    SelfNavBar.hidden = YES;
    SelfTabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self barViewSubviews];

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(passUrl:) name:@"webLink" object:nil];
    
    NSNotificationCenter *drawerCenter = [NSNotificationCenter defaultCenter];
    [drawerCenter addObserver:self selector:@selector(drawer:) name:@"drawer" object:nil];
}

- (void)passUrl:(NSNotification *)noti
{
    DetailsViewController *details = [[DetailsViewController alloc] init];
    details.firstModel = noti.object;
    [self.navigationController pushViewController:details animated:YES];
}

- (void)drawer:(NSNotification *)noti
{
    [self.sideMenuViewController presentLeftMenuViewController];
}

- (void)barViewSubviews
{
    self.barView = [[BarView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - ScreenHeight * 45 / 667)];
    self.barView.backgroundColor = RGB(22, 188, 180);
    self.barView.search.delegate = self;
    [self.view addSubview:self.barView];
    
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
    //设置成NO表示当前控件响应后会传播到其他控件上，默认为YES。
    tapGestureRecognizer.cancelsTouchesInView = NO;
    //将触摸事件添加到当前view
    [self.view addGestureRecognizer:tapGestureRecognizer];
}

#pragma mark --点击搜索方法
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    SearchBarViewController *search = [[SearchBarViewController alloc] init];
    search.urlStr = self.barView.search.text;
    [self.navigationController pushViewController:search animated:YES];
    [self.barView resignFirstResponder];
}

#pragma mark --点击空白区域searchBar回收键盘
-(void)keyboardHide:(UITapGestureRecognizer*)tap{
    [self.barView.search resignFirstResponder];
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
